import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, HttpStatus } from '@nestjs/common';
import { JournalService } from './journal.service';
import { CreateJournalDto } from './dto/create-journal.dto';
import { UpdateJournalDto } from './dto/update-journal.dto';
import { RequireLogin } from 'src/decorator/require-login.decorator';
import { LoginGuard } from 'src/login.guard';
import { PermissionGuard } from 'src/permission.guard';
import { RequirePermission } from 'src/decorator/require-permission.decorator';
import { AuthGuard } from '@nestjs/passport';
import { Request } from 'express';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';

// @ApiTags('journal') 指定 接口文档分组
@ApiTags('journal')
@Controller('journal')

@RequireLogin()
export class JournalController {
    constructor(private readonly journalService: JournalService) { }

    // 通过 @ApiOperation 描述接口的信息，@ApiResponse 描述返回值信息，@ApiQuery 描述 query 参数信息。
    // @ApiBody({
    //     type: CccDto
    // })
    @ApiOperation({ summary: '查询journal-all',description: '进行了角色鉴权' })
    @ApiResponse({
        status: HttpStatus.OK,
        description: '请求成功'
    })
    @ApiBearerAuth('bearer')
    @Get()
    @UseGuards(LoginGuard, PermissionGuard)
    @RequirePermission('查询journal')
    findAll() {
        return this.journalService.findAll();
    }

    @UseGuards(AuthGuard('jwt')) // 自动校验header中是否有token
    @Get("list")
    list(@Req() req: Request) {
        console.log(req.user); 
        return ['111', '222', '333', '444', '555']
    }
}
